package com.example.animaldoctor03;

import java.io.Serializable;
import java.util.ArrayList;

import Modle.disease.SymptomsCategorie;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import commonClass.ADAqueryNoIsAnatomySymptomsByAnimalIDActionoffz2;
import commonClass.FunctionDispatcher;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import commonClass.RemoteActionsName;

public class ZhengZhuangFZ2 extends Activity {

	// private String [] zhengzhuangfz2shuju = {"病例1" ,"病例2" ,"病例3"};
	private ListView listofzhengzhuangfz2 = null;
	// private RadioButton radiobuttonofzhengzhuangfz21 = null
	// ,radiobuttonofzhengzhuangfz22 =null ;
	private RadioButton checkedradiobutton = null;

	private RadioGroup radiogroupofzhengzhuangfz2 = null;
	//这里把要传的ID声明好
	private String animalID = "01371054603";

	
	private ArrayList<Object> resultList = null;

	//这一段时把控件都初始化好
	private void initElem() {
		setContentView(R.layout.zhengzhuangfz2);

		listofzhengzhuangfz2 = (ListView) findViewById(R.id.listofzhengzhuangfz2);

		radiogroupofzhengzhuangfz2 = (RadioGroup) findViewById(R.id.radiogroupofzhengzhuangfz2);

		radiogroupofzhengzhuangfz2.check(R.id.radiobuttonofzhengzhuangfz22); // 跳转过来默认选项是第二项对第二项进行相关的访问

		// checkedradiobutton 是拿到默认选中的值
		checkedradiobutton = (RadioButton) radiogroupofzhengzhuangfz2
				.findViewById(radiogroupofzhengzhuangfz2
						.getCheckedRadioButtonId());
		// radiobuttonofzhengzhuangfz22 =
		// (RadioButton)findViewById(radiogroupofzhengzhuangfz2.getCheckedRadioButtonId());

		// 给这个套上监听点击哪个就会跳到哪个页面上去
		radiogroupofzhengzhuangfz2
				.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(RadioGroup group, int checkedId) {
						// TODO Auto-generated method stub
						checkedradiobutton = (RadioButton) findViewById(checkedId);
						if (checkedId == R.id.radiobuttonofzhengzhuangfz21) {
							// 跳转到另一个选项的页面去
							Intent intentofzhengzhuangfz2 = new Intent(
									ZhengZhuangFZ2.this, ZhengZhuangFZ.class);
							startActivity(intentofzhengzhuangfz2);
							finish();
						} else {

						}
					}
				});

		// ArrayAdapter<String> arrayAdapterofzhengzhuangfz2 = new
		// ArrayAdapter<String>(this ,
		// android.R.layout.simple_list_item_1,zhengzhuangfz2shuju);
		// listofzhengzhuangfz2.setAdapter(arrayAdapterofzhengzhuangfz2);


	}

	//这里是包装数据 我知道是什么数据所以在后面转换时都能在得到  return的是一个list对象
	private ArrayList<Object> assembly() {

		ArrayList<Object> list = new ArrayList<Object>();

		list.add(animalID);
		// Integer i = new Integer(10);
		// list.add(i);

		return list;
	}

	//这一段是把解析好的信息显示到空件上
	private void binding(final ArrayList<Object> list) {
try{
		Log.v("ZhengZhuangFZ2", "binding:" + list.toString());
		
		String[] resultofZZFZ = new String[list.size()];
		// list.toArray(new String[list.size()]);
		for (int i = 0; i < list.size(); i++) {
			resultofZZFZ[i] = ((SymptomsCategorie) list.get(i)).getSymptomsCategorieName();
		}
		ArrayAdapter<String> arrayAdapterofResult = new ArrayAdapter<String>(
				this, android.R.layout.simple_list_item_1, resultofZZFZ);
		listofzhengzhuangfz2.setAdapter(arrayAdapterofResult);
		listofzhengzhuangfz2.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				Bundle bundleofzhengzhuangfz2 = new Bundle ();
				bundleofzhengzhuangfz2.putSerializable("shuju", (Serializable) list.get(position));
				Intent intentofzhengzhuangfz2 = new Intent(ZhengZhuangFZ2.this,
						IllnessDetail.class);
				intentofzhengzhuangfz2.putExtras(bundleofzhengzhuangfz2);
				startActivity(intentofzhengzhuangfz2);
				finish();
				
			}
		});
		}catch(NullPointerException e){
			android.app.AlertDialog.Builder builderofZZFZ2 = new AlertDialog.Builder(ZhengZhuangFZ2.this);
			builderofZZFZ2.setMessage("无数据，请用其他功能");
			builderofZZFZ2.create().show();
		}

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initElem();

		ArrayList<Object> parasList = assembly();

		final ArrayList<Object> resultListT = null;

		ADAqueryNoIsAnatomySymptomsByAnimalIDActionoffz2 iAction = new ADAqueryNoIsAnatomySymptomsByAnimalIDActionoffz2();

		FunctionDispatcher functionDispacher = new FunctionDispatcher();
try{
		functionDispacher.exceute(
				RemoteActionsName.QuerySymptomsCategorieByAnimalID, parasList,
				iAction, new IRequestCompeletListener() {

					@Override
					public void doCompelet(ArrayList<Object> resultList) {
						// TODO Auto-generated method stub
						
						Log.v("ZhengZhuangFZ2", "post:" + resultList.toString());
						ZhengZhuangFZ2.this.resultList = resultList;
						binding(resultList);
					}
				},this);}catch(NullPointerException e){
					
					android.app.AlertDialog.Builder builderofZZFZ2f = new AlertDialog.Builder(ZhengZhuangFZ2.this);
					builderofZZFZ2f.setMessage("无返回值,请用其他功能");
					builderofZZFZ2f.create().show();
				}

	}

	class itemonclicklistenerofzhengzhuangfz2 implements OnItemClickListener {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			// TODO Auto-generated method stub


		}

	}
}
